import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.DateFormat;


public class CallRow {
    private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("H:mm:ss");

    private long customerId;
    private long destinationNumber;

    private final Date dateTime;
    private final double durationMin;
    private final long durationSec;

    public CallRow(long customerId, final Date dateTime, long destinationNumber, double durationMin) {
        this.customerId = customerId;
        this.dateTime = dateTime;
        this.destinationNumber = destinationNumber;

        this.durationMin = durationMin;
        this.durationSec = Math.round(durationMin * 60);
    }

    public CallRow(long customerId, final Date dateTime, long destinationNumber, long durationSec) {
        this.customerId = customerId;
        this.dateTime = dateTime;
        this.destinationNumber = destinationNumber;

        this.durationMin = roundToMin(durationSec);
        this.durationSec = durationSec;
    }

    public double roundToMin(long durationSec) {
        int fraction  = (int) (60 * 0.2);
        return (Math.ceil((double) durationSec / fraction) * fraction) / 60;
    }


    public long getCustomerId() {
        return customerId;
    }

    public void setCustomerId(long id) {
        this.customerId = id;
    }

    public Date getDateTime() throws ParseException {
        return new Date(dateTime.getTime());
    }

    public String getTime() throws ParseException {
        return TIME_FORMAT.format(getDateTime());
    }

    public String getDestNumber() {
        return Long.toString(destinationNumber);
    }

    public double getDurationMin() {
            return durationMin;
    }

    public long getDurationSec() {
        return durationSec;
    }

    public String toString() {
        return "{" +
                "customerId=" + customerId +
                ", dateTime=" + dateTime +
                ", destinationNumber=" + destinationNumber +
                ", durationMin=" + durationMin +
                ", durationSec=" + durationSec +
                '}';
    }


    public void setDestinationNumber(long destinationNumber) {
        this.destinationNumber = destinationNumber;
    }
}